package com.dannypatterson.airinstaller {
	
	import flash.desktop.NativeApplication;
	import flash.events.BrowserInvokeEvent;
	import flash.net.LocalConnection;
	
	import mx.controls.Alert;
	
	/**
	 * This object should be created upon initialization of the AIR application
	 * and is used to send notifications back the the BrowserInstaller via Local
	 * Connection to let it know the AIR application has successfully launched
	 * or installed/updated.
	 * 
	 * @author Danny Patterson
	 */
	public class LaunchNotifier {
		
		private var connection:LocalConnection;
		
		public function LaunchNotifier() {
			connection = new LocalConnection();
			NativeApplication.nativeApplication.addEventListener(BrowserInvokeEvent.BROWSER_INVOKE, onBrowserInvoke);
		}
		
		private function onBrowserInvoke(event:BrowserInvokeEvent):void {
			Alert.show("BROWSER_INVOKE: " + event.arguments.toString());
			if(event.arguments.pop() == "installNotify") {
				connection.send("_launchNotify", "onInstallNotify", NativeApplication.nativeApplication.applicationID);
			}else {
				connection.send("_launchNotify", "onLaunchNotify", NativeApplication.nativeApplication.applicationID);
			}
		}

	}
	
}